const path = require("path");
const fs = require("fs-extra");
const buffer = require("buffer");
var MultiStream = require('multistream');
const jsonBeautify = require("json-beautify");
const Toolbox = require("../tool/toolbox");
const lib = require("../lib");
// new MultiStream([
//   fs.createReadStream(path.join(__dirname, "../tmp/1KB.jpg")),
//   fs.createReadStream(path.join(__dirname, "../tmp/EEE.zip")),
// ]).pipe(fs.createWriteStream(path.join(__dirname, "../tmp", "test-zip.jpg")));

// https://coding-net-production-file-ci.codehub.cn/bf3e25b0-a743-11ea-ac7a-7374110578f9.jpg?attname=EEE-JPG.zip&sign=Q2sTykAWED7Ufmiz7GbNjdbcivZhPTEyNTcyNDI1OTkmaz1BS0lEYXk4M2xGbWFTNlk0TFRkek1WTzFTZFpPeUpTTk9ZcHImZT0xNTkxNTg4MDAzJnQ9MTU5MTM3MjAwMyZyPTUxNDIyNTY5JmY9L2JmM2UyNWIwLWE3NDMtMTFlYS1hYzdhLTczNzQxMTA1NzhmOS5qcGcmYj1jb2RpbmctbmV0LXByb2R1Y3Rpb24tZmlsZQ==

let session = "K2kwd2ppNy9sVHpFdmVmRzJYL1lJdXBvVndoNnoxYklIN09IQmlEVkNzZnduSkZTWlBhYWUzS0tCeWNUek5BRnhVa251bFZteVhZcnZSa1VaQUs1ZVVRRWVxT3dtY3dlMHVUUFcrNjVvaUM1b3dyeDdXMjVPQktRdXl5OVZYSFBOekZPdml1NDJQcjNoeEZLbFgzbXBxbkJ3N0c3eTRBZ2pqdEtCaFJ0V3B2blhyQlBaSmVGV0NhV21ZWWxpeGNjQXVXYVFOWWpiaUdKbEt3UUpUS0t5SWNYS2VIOHdOTlNqS2oycUxOS202ZGNaS0JmQnV6MzdYcGpRcTZ6RkJLNDlwMFFkZm52aEpmRHpRdU5OLzROZ0M3WFZobFJYOUFqWVYyaU8rMFZOeUVkeHJnNVJJSERkQlBpS1lpR0tKeU1MT1o0c3MwV2UrUUZ4aFN6TzV0NUU1R0lnbTZxVEYzcDFzZUxQdWw3TG0yN3pLUksyTXc5VHJpN0VvZmJubis2Q3pRaGlEb0ZZZ2VlU2hEV3REYTZLKzNVUHVKb3ozQk8rNkFob1NiRlgzb1NIRlZ1blkxdThYNjBHU05keWt5RC0tKzliUm9DNkFlUEk2ekFKWUx1eVRhQT09--83e381ddc956663826781aa279cd1ac983c8f5fb";


// for (let i = 3; i <= 19; i++) {
//   let baifenshu = 1 / i * 100;
//   let tmp = baifenshu * 10;
//   tmp = Math.round(tmp);
//   baifenshu = tmp / 10
//   console.log(`1/${i}`, "|", `${baifenshu}%`, "|", "null")

// }



// return;
lib.GetGiteeBySession(session)
  .then(async VV => {
    // debugger
    let gitee = VV.data.gitee;
    // let lib_qiniu = require("../plugins/uploadJson");
    // // let testJsonBuf = (await fs.readFile(path.join(__dirname,"./太大/200626_23少女映画103套27G.txt")));
    // // let o_l = await lib_qiniu.uploadJsonStringBuffer(testJsonBuf);
    // let o_listdir = await Toolbox.safeListDir(path.join(__dirname, "./太大"));
    // for (let x of o_listdir) {
    //   debugger
    //   if (!x.full_path.endsWith(".txt")) {
    //     continue;
    //   }
    //   let buf = (await fs.readFile(x.full_path));
    //   let upbuf = await lib_qiniu.uploadJsonStringBuffer(buffer.Buffer.from(JSON.stringify(JSON.parse(buf.toString()))));
    //   if (!upbuf.ok) {
    //     console.log(x.relative_path, upbuf.msg);
    //     continue;
    //   }
    //   let obj = {
    //     type: "Link_Hunliji",
    //     data: {
    //       link: upbuf.data.link
    //     }
    //   }
    //   let str = jsonBeautify(obj,null,2,100);
    //   let o_create = await gitee.createIssue0819("yaby007/ERO_PIC_PARK",x.relative_path.replace(".txt",""),str);
    //   if(!o_create.ok){
    //     console.log(x.relative_path,o_create.msg);
    //     continue;
    //   }
    //   console.log(x.relative_path,"!!!DONE!!!");
    // }

    // debugger
    // process.exit();
    // let o_get = await gitee.getWikiContent("yaby007/ERO_PIC_PARK", 2292767);
    while (true) {
      let o_list = await gitee.getIssueList0819("yaby007/ERO_PIC_PARK");
      let toDel = o_list.data.issues.filter(e => e.title.startsWith("201124_"));
      if (toDel.length == 0) {
        debugger
        break;
      }
      for (let x of toDel) {
        console.log(x.title);
        let change = await gitee.changeIssueToYiwancheng102("yaby007/ERO_PIC_PARK", x.issue_number);
        if(!change.ok){
          debugger
        }else{

        }
      }
    }

    debugger
    let o_get = await gitee.getIssueDetail0819("yaby007/ERO_PIC_PARK", o_list.data.issues[0].issue_number);
    let o_create = await gitee.createIssue0819("yaby007/ERO_PIC_PARK", `"yaby007/ERO_PIC_PARK""yaby007/ERO_PIC_PARK""yaby007/ERO_PIC_PARK""yaby007/ERO_PIC_PARK""yaby007/ERO_PIC_PARK""yaby007/ERO_PIC_PARK""yaby007/ERO_PIC_PARK"`, "sjsjsjsjjsjsjsj")
    debugger
    let o_import = await gitee.importAsWikiPage("yaby007/test", "TESTSVJHJ♥", `
      
  天翼上传 3350
        
  G:\\ERO0530\\extract1\\\(同人CG集\) \[おばんざい☆スタジオ\] 絶対奴隷宣言～真面目母娘の淫らな調教性活～.zip
        
  
        
  ---
        
  
    
   公开URL : http://ty-file.liblu.me/ps/drive/a/3350/d/7149639417270115/p/1
    
        
   自己用 : http://ty-file.liblu.me/drive/a/3350/d/7149639417270115/p/1
        
  
        `)
    debugger
  })

